package cn.tt.tuantuanerp.tuantuanerp.warehouse.controller;


import cn.tt.tuantuanerp.tuantuanerp.comment.pojo.vo.WarehouseCheckVO;
import cn.tt.tuantuanerp.tuantuanerp.comment.security.LoginPrincipal;
import cn.tt.tuantuanerp.tuantuanerp.comment.web.JsonPage;
import cn.tt.tuantuanerp.tuantuanerp.comment.web.JsonResult;
import cn.tt.tuantuanerp.tuantuanerp.warehouse.service.IWarehouseCheckService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;


/**
 * 用户控制层
 *
 * @author gudiwen
 * @version 0.0.1
 */
@Api(tags = "8.盘点批次")
@RestController
@RequestMapping("/pareHouse")
@Slf4j
public class WarehouseCheckController {
    @Autowired
    private IWarehouseCheckService warehouseCheckService;
    @GetMapping("")
    @ApiOperationSupport(order = 420)
    @ApiOperation("查询盘点列表模块")
    public JsonResult<JsonPage<WarehouseCheckVO>> list(Integer startIndex, Integer pageSize){
        log.debug("开始处理[查询盘点批次列表]的请求");

        return JsonResult.ok(warehouseCheckService.list(startIndex,pageSize));
    }

    @GetMapping("/{checkWarehouseId:[0-9]+}")
    @ApiOperationSupport(order = 421)
    @ApiOperation("通过ID查询盘点批次信息")
    public JsonResult<WarehouseCheckVO> getStandWarehouseById(@PathVariable Long checkWarehouseId){
        log.debug("开始处理[通过盘点批次号查询盘点批次]的请求"+checkWarehouseId);
        WarehouseCheckVO standardById = warehouseCheckService.getStandardById(checkWarehouseId);
        return JsonResult.ok(standardById);
    }

    @GetMapping("/getCheckId")
    @ApiOperationSupport(order = 422)
    @ApiOperation("获取合适的新增盘点批次ID")
    public JsonResult<Long> getId(@ApiIgnore @AuthenticationPrincipal LoginPrincipal loginPrincipal){
        log.debug("开始处理[查询盘点批次列表]的请求");
        Long aLong = warehouseCheckService.returnID(loginPrincipal);
        return JsonResult.ok(aLong);
    }

    @PostMapping("/{checkWarehouseId:[0-9]+}/updateEnable")
    @ApiOperationSupport(order = 430)
    @ApiOperation("修改审批状态")
    public JsonResult<Void> updateEnable(@PathVariable  Long checkWarehouseId){

        log.debug("开始处理[审批]请求");
        log.debug("checkId:{}",checkWarehouseId);
        warehouseCheckService.setCheckPass(checkWarehouseId);
        return JsonResult.ok();
    }

}
